public  class Cbl_ReturnMachineUpdateYQ {

	public static void ReturnMachineUpdateYQ(List<Return_Machine__c> list_new,Map<Id,Return_Machine__c> map_old)
	{
		for(Return_Machine__c rm: list_new)
		{
			Return_Machine__c oldrm=map_old.get(rm.Id);
			if(rm.Status__c!=oldrm.Status__c && rm.Status__c=='已批准')
			{
				if(rm.instrument__c!=null)
				{
					Equipment__c eqp=new Equipment__c(
									id=rm.instrument__c
									,type__c=rm.Type__c
									,OpponentStatus__c = '使用后停用');

					update eqp;
					Approval.lock(eqp,false);

					//重新计算合同仪器的退机数量
					List<Return_Machine__c> rms = [select Id ,Instrument__r.ContractInstruments__c from Return_Machine__c 
					where  Instrument__r.ContractInstruments__c != null and Id =:rm.Id ];

				
					if(!rms.isEmpty())ContractCalcEquipmentUtil.returnBackToContract(rms[0].Instrument__r.ContractInstruments__c);
				}
			}
		}



	}



 
    
}